package com.hospital.demo.controller.jiashuai;

import com.alibaba.fastjson.JSON;
import com.hospital.demo.model.jiashuai.Worker;
import com.hospital.demo.service.jiashuai.IWorkerService;
import com.hospital.demo.util.ResultUtils;
import com.hospital.demo.util.ResultVO;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;


@RestController
@RequestMapping("/worker")
public class WorkerController {
    @Autowired
    private IWorkerService iWorkerService;

    /**
     * 查询所有医护人员
     */
    @GetMapping("/list")//查询
    public ResultVO list() {
        List<Worker> list = iWorkerService.selectWorker();
        return ResultUtils.success(list);
    }

    /**
     * 按照部门id和诊室查找医护人员
     */
    @GetMapping("/searchworker")
    public ResultVO searchworker(int deptnoid, String mname) {
        Worker worker = new Worker();
        if (deptnoid != 0) {
            worker.setDeptnoid(deptnoid);
        }
        if (!mname.equals("all")) {
            worker.setMname(mname);
        }
        List<Worker> list = iWorkerService.selectWorkerByProId(worker);
        return ResultUtils.success(list);
    }

    /**
     * 添加医护人员
     */
    @PostMapping("/saveworker")
    public ResultVO saveworker(Worker worker) {
        iWorkerService.insertworker(worker);
        return ResultUtils.success();
    }

    /**
     * 删除医护人员
     */
    @GetMapping("/deleteworker")
    public ResultVO deleteworker(Integer id) {
        iWorkerService.deleteworker(id);
        return ResultUtils.success();

    }

    /**
     * 查看单个医护人员
     */
    @GetMapping("/viewworker")
    public ResultVO viewworker(Integer idd) {
        Worker worker = iWorkerService.get(idd);
        return ResultUtils.success(Arrays.asList(worker));
    }

    /**
     * 更新医护人员
     */
    @PostMapping("/updateworker")
    public ResultVO updateworker(Worker worker) {
        iWorkerService.updateworker(worker);
        return ResultUtils.success();
    }


}
